package com.tianxiabuyi.weixin.common.exception;

import com.tianxiabuyi.Message;

/**
 * 微信异常
 */
public class WxRuntimeException extends RuntimeException {

    private int code;
    private String message;
    private Message wxError;

    public WxRuntimeException(int code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public WxRuntimeException(Message wxError) {
        super(wxError.toJson());
        this.wxError = wxError;
    }

    public int getCode() {
        if (this.wxError != null) {
            return wxError.getErrcode();
        } else {
            return code;
        }
    }

    public String message() {
        if (this.wxError != null) {
            return wxError.getErrmsg();
        } else {
            return this.message;
        }
    }

    public Message getWxError() {
        return this.wxError;
    }

}
